// 两个数组的交集
var intersection = function (nums1, nums2) {
  const map = new Map();
  for (const left of nums1) {
    map.set(left, 1);
  }
  let ans = [];
  for (const right of nums2) {
    const _right = map.get(right);
    if (_right === 1) {
      ans.push(right);
      map.set(right, 0);
    }
  }
  return ans;
};

const ans = intersection([1, 2, 2, 1], [2, 2, 1, 3]);
console.log("ans: ", ans);
